<cfcomponent>

	<!------>

	<cffunction name="init" access="public" output="false" returntype="any" hint="Constructor for this cfc">
		<cfreturn this/>
	</cffunction>

	<!------>

	<cffunction name="getDsn" access="private" output="false" returntype="string">
		<cfreturn session.dsn/>
	</cffunction>

	<!--- Get Database Info --->
	<cffunction name="getColumns" displayname="Get Columns" hint="Return column data from specified table" access="public" output="false" returntype="query">
		<cfargument name="table" required="true" />

		<cfset var local = {} />

	    <cfdbinfo datasource=#getDSN()#
	      name="local.retVar"
	      type="columns"
	      table="#arguments.table#">

	    <cfreturn local.retVar />

	</cffunction>

	<!------>

	<cffunction name="columnTypeDetails" access="private" output="false" returntype="string">
		<cfargument name="typeName" required="true" />

		<cfset var local = {} />
		<cfset local.type_name = arguments.typeName />

		<cfswitch expression="#local.type_name#">
	        <cfcase value="int unsigned, int signed, tinyint unsigned, tinyint signed">
	            <cfset local.columnType = "numeric">
	        </cfcase>
	        <cfcase value="varchar, char, text, nvarchar, nchar, ntext">
	            <cfset local.columnType = "string">
	        </cfcase>
	        <cfcase value="bit">
	            <cfset local.columnType = "boolean">
	        </cfcase>
	        <cfcase value="date">
	            <cfset local.columnType = "date">
	        </cfcase>
	        <cfdefaultcase>
	            <cfset local.columnType = "any">
	        </cfdefaultcase>
	    </cfswitch>

		<cfreturn local.columnType />

	</cffunction>

	<!------>

	<cffunction name="getFieldType" access="private" output="false" returntype="string">
		<cfset var local = {} />


	</cffunction>

	<!------>

	<cffunction name="getPrimaryGenerator" access="private" output="false" returntype="string">
		<cfset var local = {} />

		increment|identity
    |sequence|sequence-identity|seqhilo
    |uuid|guid|native|[assigned]|select|foreign

	</cffunction>

	<!------>

	<cffunction name="getRelationshipType" access="private" output="false" returntype="string">
		<cfset var local = {} />

		one-to-one

		one-to-many

		many-to-one

		many-to-many
	</cffunction>

	<!------>

	<cffunction name="getORMDataType" access="private" output="false" returntype="string">

		<cfset var local = {} />

      string

      character

      char

      short

      integer

      int

      long

      big_decimal

      float

      double

      Boolean

      yes_no

      true_false

      text

      date

      timestamp

      binary

      serializable

      blob

      clob


	</cffunction>

	<!------>

	<cffunction name="generateProperties" access="public" returntype="string" hint="Generate code for the model component">
		<cfargument name="table" required="true" />

		<cfset var local = {} />

		<cfset local.tableColumns = getColumns(arguments.table)>

		<cfsavecontent variable="local.generatedModel"><cfoutput><cfprocessingdirective suppresswhitespace="true">
	       <cfloop query="local.tableColumns">
				<cfsilent>
				<cfset local.columnType = columnTypeDetails(local.tableColumns.type_name) />
	            <cfset local.isRequired = "">
				<cfset local.realDelete="true">
	            <!--- lets check for few certain fields if we do have those fields then we remove the delete function --->
				<cfif local.tableColumns.column_name eq "is_active">
					<cfset local.realDelete="false">
				</cfif>
			</cfsilent>
	        <%cfproperty name="#local.tableColumns.column_name#" displayname="#local.tableColumns.column_name#" type="#local.columnType#" sqltype="#lcase(local.tableColumns.type_name)#" required="false"/>
	        </cfloop>
		</cfprocessingdirective></cfoutput></cfsavecontent>
		<cfreturn trim(local.generatedModel)>
	</cffunction>

	<!------>

</cfcomponent>